<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:wh="http://java.sun.com/jsf/composite/wh"
	xmlns:p="http://primefaces.org/ui">
<h:body>
	<ui:composition template="template/companyTemplate.xhtml">
		<ui:define name="companyContent">

			<h1>Chosen products for sale</h1>
			<h:form id="companySelectedProduct" styleClass="horizontal_full">
				<p>
					Here you can see the products which you want to sell. You have
					chosen it before from the
					<p:link value="Product Overview mask"
						outcome="companyProductOverview?faces-redirect=true" />
					. Here it is possible to remove it again or to set the selling
					price. After you have set the price it is important to save and
					reload your products. 
					Be careful with the number of products you want to provide for the customers. 
					If you choose too much, you have to pay additional logistic costs. 
					They can be seen on the bottom of the table.
				</p>
				<p:dataTable id="compProdTable" var="compProd"
					value="#{companyMBean.companyProducts}" selectionMode="single"
					rowKey="#{compProd.id}"
					paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {Exporters}"
					rowsPerPageTemplate="10,25,50,100" paginator="true" rows="10"
					resizableColumns="true">

					<f:facet name="header">
					            Chosen products for sale - overview
					        </f:facet>
					
					<f:facet name="{Exporters}">
						<h:commandLink>
							<p:graphicImage library="img" name="excel.png" width="24" />
							<p:dataExporter type="xls" target="compProdTable"
								fileName="compProdTable" />
						</h:commandLink>
						<h:commandLink>
							<p:graphicImage library="img" name="pdf.png" width="24" />
							<p:dataExporter type="pdf" target="compProdTable"
								fileName="compProdTable" />
						</h:commandLink>
					</f:facet>
					
					<p:column headerText="Delete product" exportable="false" width="12%">
						<p:commandButton icon="ui-icon-trash" title="Delete Product"
							action="#{companyMBean.actionDeleteCompanyProduct()}"
							update="compProdTable">
							<f:setPropertyActionListener value="#{compProd}"
								target="#{companyMBean.selectedCompanyProduct}" />
						</p:commandButton>
					</p:column>

					<p:column headerText="Name" sortBy="#{compProd.product.name}" width="30%">
						<h:outputText value="#{compProd.product.name}" />
					</p:column>

					<p:column headerText="Costs"
						sortBy="#{compProd.product.productCosts}" width="10%">
						<h:outputText value="#{compProd.product.productCosts}" />
					</p:column>

					<p:column headerText="Quality"
						sortBy="#{compProd.product.qualityFactor}" width="12%">
						<p:rating id="qualityRating" value="#{compProd.product.getQualityFactorStars()}" stars="5" readonly="true" />
					</p:column>

					<p:column headerText="Supplier"
						sortBy="#{compProd.product.supplier.supplierName}" width="12%">
						<h:outputText value="#{compProd.product.supplier.supplierName}" />
					</p:column>

					<p:column headerText="Selling price"
						sortBy="#{compProd.sellingPrice}" width="12%">
						<h:inputText value="#{compProd.sellingPrice}"
							converterMessage="Selling price has to be a positive number."
							validatorMessage="Selling price has to be a positive number.">
							<f:validateLongRange minimum="0" />
						</h:inputText>
					</p:column>

					<p:column headerText="Product details" exportable="false" width="12%">
						<p:commandButton icon="ui-icon-search" title="View"
							action="#{companyMBean.actionShowProductDetail()}">
							<f:setPropertyActionListener value="#{compProd.product}"
								target="#{companyMBean.selectedProduct}" />
						</p:commandButton>
					</p:column>

					<f:facet name="footer">
						<p:commandButton value="Save price settings"
							actionListener="#{companyMBean.actionSaveAndRefreshAllCompanyProducts}"
							update="compProdTable" icon="ui-icon-disk" />
							
						<h:outputText value=" Additional Portfolio Costs: #{companyMBean.getPortfolioCosts()}" />
					</f:facet>
				</p:dataTable>
				
				
				
			</h:form>

		</ui:define>
	</ui:composition>
</h:body>
</html>